//
// DotNetNuke - http://www.dotnetnuke.com
// Copyright (c) 2002-2010
// by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
using DotNetNuke.Services.Localization;
namespace DotNetNuke.UI.Skins.Controls
{
	public class ModuleMessage : UI.Skins.SkinObjectBase
	{
		public enum ModuleMessageType
		{
			GreenSuccess,
			YellowWarning,
			RedError,
			BlueInfo
		}
		private string _text;
		private string _heading;
		private ModuleMessageType _iconType;
		private string _iconImage;
		protected System.Web.UI.WebControls.Label lblMessage;
		protected System.Web.UI.WebControls.Label lblHeading;
		protected System.Web.UI.WebControls.Image imgIcon;
		protected System.Web.UI.WebControls.Image imgLogo;
		public string Text
		{
			get { return _text; }
			set { _text = value; }
		}
		public string Heading
		{
			get { return _heading; }
			set { _heading = value; }
		}
		public ModuleMessageType IconType
		{
			get { return _iconType; }
			set { _iconType = value; }
		}
		public string IconImage
		{
			get { return _iconImage; }
			set { _iconImage = value; }
		}
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);

			try
			{
				string strMessage = "";
				if (!String.IsNullOrEmpty(IconImage))
				{
					strMessage += this.Text;
					lblHeading.CssClass = "SubHead";
					lblMessage.CssClass = "Normal";
					imgIcon.ImageUrl = IconImage;
					imgIcon.Visible = true;
				}
				else
				{
					switch (IconType)
					{
						case UI.Skins.Controls.ModuleMessage.ModuleMessageType.GreenSuccess:
							strMessage += this.Text;
							lblHeading.CssClass = "SubHead";
							lblMessage.CssClass = "Normal";
							imgIcon.ImageUrl = "~/images/green-ok.gif";
							imgIcon.Visible = true;
							imgIcon.AlternateText = Localization.GetString(UI.Skins.Controls.ModuleMessage.ModuleMessageType.GreenSuccess.ToString());
							imgIcon.ToolTip = Localization.GetString(UI.Skins.Controls.ModuleMessage.ModuleMessageType.GreenSuccess.ToString());
							break;
						case UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning:
							strMessage += this.Text;
							lblHeading.CssClass = "Normal";
							lblMessage.CssClass = "Normal";
							imgIcon.ImageUrl = "~/images/yellow-warning.gif";
							imgIcon.Visible = true;
							imgIcon.AlternateText = Localization.GetString(UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning.ToString());
							imgIcon.ToolTip = Localization.GetString(UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning.ToString());
							break;
						case UI.Skins.Controls.ModuleMessage.ModuleMessageType.BlueInfo:
							strMessage += this.Text;
							lblHeading.CssClass = "Normal";
							lblMessage.CssClass = "Normal";
							imgIcon.ImageUrl = "~/images/blue-info.gif";
							imgIcon.Visible = true;
							imgIcon.AlternateText = Localization.GetString(UI.Skins.Controls.ModuleMessage.ModuleMessageType.BlueInfo.ToString());
							imgIcon.ToolTip = Localization.GetString(UI.Skins.Controls.ModuleMessage.ModuleMessageType.BlueInfo.ToString());
							break;
						case UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError:
							strMessage += this.Text;
							lblHeading.CssClass = "NormalRed";
							lblMessage.CssClass = "Normal";
							imgIcon.ImageUrl = "~/images/red-error.gif";
							imgIcon.Visible = true;
							imgIcon.AlternateText = Localization.GetString(UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError.ToString());
							imgIcon.ToolTip = Localization.GetString(UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError.ToString());
							break;
					}
				}
				lblMessage.Text = strMessage;
				if (!String.IsNullOrEmpty(Heading))
				{
					lblHeading.Visible = true;
					lblHeading.Text = Heading + "<br/>";
				}
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc, false);
			}
		}
	}
}
